package com.gitee.wsl.compose.chart.xy.bar.group

import androidx.compose.ui.graphics.Color
import com.gitee.wsl.compose.chart.xy.bar.Bar
import com.gitee.wsl.compose.chart.xy.bar.BarComposable
import com.gitee.wsl.compose.chart.xy.bar.VerticalBarPlotScope
import com.gitee.wsl.compose.chart.xy.bar.VerticalBarPlotScopeImpl
import com.gitee.wsl.compose.chart.xy.bar.solidBar

/**
 * Receiver scope used by [GroupedVerticalBarPlot].
 */
 interface GroupedVerticalBarPlotScope<X, Y> {
    /**
     * Starts a new series of bars to be plotted, with a [defaultBar] to use for rendering all
     * bars in this series.
     */
     fun series(
        defaultBar: BarComposable = Bar.solidBar(Color.Blue),
        content: VerticalBarPlotScope<X, Y>.() -> Unit
    )
}

internal class GroupedVerticalBarPlotScopeImpl<X, Y> : GroupedVerticalBarPlotScope<X, Y> {
    val series: MutableList<VerticalBarPlotScopeImpl<X, Y>> = mutableListOf()
    override fun series(defaultBar: BarComposable, content: VerticalBarPlotScope<X, Y>.() -> Unit) {
        val scope = VerticalBarPlotScopeImpl<X, Y>(defaultBar)
        series.add(scope)
        scope.content()
    }
}